package com;

import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONWriter.Feature;
import com.entity.CDNParam;
import com.entity.FormParam;
import com.entity.MusicInfoParam;
import com.entity.SearchParam;
import com.utils.CryptoUtil;

/**
 * Hello world!
 */
public class App {

    public static void main(String[] args) {
        // 通过关键词查找音乐
        // getMusicByWord();

        // 查找CDN服务器
        // getCDNServer();

        // 获取音乐信息
        getMusicInfo();
    }

    /**
     * 通过关键词查找音乐
     * 请求接口：https://music.163.com/weapi/search/suggest/web
     */
    public static void getMusicByWord() {
        String keyWord = "";

        if (StrUtil.isBlank(keyWord)) {
            System.out.println("查询参数不能为空!");
            return;
        }

        // 构建查询参数
        SearchParam searchParam = new SearchParam();
        searchParam.setParam(keyWord);
        searchParam.setLimit(8);

        FormParam formParam = CryptoUtil.encrypt(searchParam);
        System.out.println(JSON.toJSONString(formParam, Feature.PrettyFormat));
    }

    /**
     * 获取音乐信息
     * 请求接口：https://music.163.com/weapi/song/enhance/player/url/v1
     */
    public static void getMusicInfo() {
        String[] musicIds = {"93666"};

        MusicInfoParam musicInfoParam = new MusicInfoParam();
        musicInfoParam.setIds(musicIds);
        musicInfoParam.setLevel("standard");
        musicInfoParam.setEncodeType("aac");

        FormParam formParam = CryptoUtil.encrypt(musicInfoParam);
        System.out.println(JSON.toJSONString(formParam, Feature.PrettyFormat));
    }

    /**
     * CDN服务器查询
     * 请求接口：https://music.163.com/weapi/cdns
     */
    public static void getCDNServer() {
        CDNParam cdnParam = new CDNParam();
        cdnParam.setCsrfToken("");

        FormParam formParam = CryptoUtil.encrypt(cdnParam);
        System.out.println(JSON.toJSONString(formParam, Feature.PrettyFormat));
    }
}
